using MultiAgentsClient.Service.WorkflowEngine.BaseNodes;
using MultiAgentsClient.Shared;

namespace MultiAgentsClient.Service.WorkflowEngine.BuiltInNodes;

/// <summary>
/// This node is a trigger node, not meant to have any logic
/// </summary>
[NodeGraphPortDef(0, 1)]
public class UserInputNode : BaseNode
{
    [NodeGraphParam] public bool IncludeChatHistory;
    [NodeGraphOutput] public string UserInput = "";
    [NodeGraphOutput] public string UserChatHistory = "";

    public UserInputNode() : base()
    {
    }

    public override void Dispose()
    {
    }

    //at the end of execution it should return something? or another method should. 
    public override async Task<NodeOutcome> ExecuteNodeAsync()
    {
        return await Task.FromResult(new NodeOutcome(NodeOutcomeStatus.Success, 0));
    }

    public void PassUserInput(string userInput, List<LlmMessageSimp>? chatHistory)
    {
        UserInput = userInput;
        runtimeContext.SetVar(Id, () => UserInput);
        if (IncludeChatHistory && chatHistory != null)
        {
            var chatHistoryStr = "";
            foreach (var chat in chatHistory)
            {
                chatHistoryStr += chat.ToString();
            }
            UserChatHistory = chatHistoryStr;
            runtimeContext.SetVar(Id, () => UserChatHistory);
        }
    }
}
